try:
    lock.acquire()
    #关键部分
    ...
finally:
    lock.release()


with lock:
    #关键部分
    ...

with lock_A:
    #关键部分
    ...
    with lock_B:
        #B的关键部分
        ...